
public class test {
    private double firstNumber;
    private double difference;
    private int sequenceLength;

    public test(double firstNumber, double difference, int sequenceLength) {
        this.firstNumber = firstNumber;
        this.difference = difference;
        this.sequenceLength = sequenceLength;
    }

    public double calculateSum() {
        return sequenceLength / 2.0 * (2 * firstNumber + (sequenceLength - 1) * difference);
    }


    public static void main(String[] args) {
        test sequence = new test(1, 2, 5); // 例如：首项为1，公差为2，共有5项
        System.out.println("等差数列的总和为: " + sequence.calculateSum());
    }
}
